/*!
 * nodeclub - route.js
 * Copyright(c) 2012 fengmk2 <fengmk2@gmail.com>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

import express from 'express';
import passport from 'passport';
import * as sign from './controllers/sign';
import * as user from './controllers/user';
import * as message from './controllers/message';
import * as topic from './controllers/topic';
import * as reply from './controllers/reply';
import * as zone from './controllers/zone';
import * as menu from './controllers/menu';
import * as search from './controllers/search';
import * as profile from './controllers/profile';
import * as audio from './controllers/audio';
import * as static2 from './controllers/static';
import * as repo from './controllers/repo';
import { zonesRequired } from './middlewares/base_data';
import { authRequired, supportRequired, adminRequired, userRequired } from './middlewares/auth';

const router = express.Router();

 // 获取 topics数据
router.post('/topics', topic.topics);

// sign controller
router.post('/user/tryAuth', sign.tryAuth);
// router.post('/user/accesstoken', auth.tryAuth,  sign.accesstoken);
router.post('/user/signup', sign.signup);  // 提交注册信息
router.post('/user/signin', sign.signin);  // 登录校验
router.post('/user/signout', sign.signout);

router.post('/user/createSearchPassword', sign.createSearchPassword);                 // 触发找回密码命令
router.post('/user/authSearchPassword', sign.authSearchPassword);
router.post('/user/:uid/resetPassword', userRequired, sign.updateResetPassword);    // 重置密码

// user controller
router.post('/user/:uid/topics', userRequired, topic.userTopics);
router.post('/user/:uid/update', userRequired, user.update);         // 提交个人信息设置
router.post('/user/:uid/detail', userRequired, user.detail);         // 获取用户信息
router.post('/user/:uid/collectTopics', userRequired, zonesRequired, topic.collectTopics);  // 获取用户的收藏文章
router.post('/user/set_star', adminRequired, user.toggleStar);       // 把某用户设为达人
router.post('/user/cancel_star', adminRequired, user.toggleStar);    // 取消某用户的达人身份
router.post('/user/block', adminRequired, user.block);         // 禁言某用户
router.post('/user/list', adminRequired, user.users);
router.post('/user/updateRole', adminRequired, user.updateRole);

// topic
router.post('/topic/checkStatus', topic.checkStatus);
router.post('/topic/:tid/data', topic.data);                        // 获取单个topic
router.post('/topic/:tid/top', adminRequired, topic.top);          // 将某话题置顶
router.post('/topic/:tid/good', adminRequired, topic.good);         // 将某话题加精
router.post('/topic/:tid/status', userRequired, topic.status);        // 更新话题状态
router.post('/topic/:tid/lock', adminRequired, topic.lock);         // 锁定主题，不能再回复
router.post('/zone/:key/:template/topic/create', userRequired, topic.create);        // 保存新建的文章
router.post('/topic/:tid/delete', userRequired, topic.del);
router.post('/zone/:key/:template/topic/:tid/edit', userRequired, topic.update);
router.post('/topic/collect', userRequired, topic.collect);       // 关注某话题
router.post('/topic/delCollect', userRequired, topic.delCollect);    // 取消关注某话题

// reply controller
router.post('/:tid/replies/data', reply.replies);                     // 获取回复列表
router.post('/reply/:tid/reply', userRequired, reply.add);           // 提交一级回复
router.post('/reply/:reply_id/edit', userRequired, reply.update);        // 修改某评论
router.post('/reply/:reply_id/delete', userRequired, reply.del);           // 删除某评论
router.post('/reply/:reply_id/up', userRequired, reply.up);            // 为评论点赞
router.post('/upload', userRequired, topic.upload);        // 上传图片

// message controller
router.post('/message/unread/count', userRequired, message.unreadCount);
router.post('/message/data', userRequired, message.userMessages);
router.post('/message/read', userRequired, message.read);

// zone
router.post('/zone/full', adminRequired, zone.getFullZones);
router.post('/zone/data', zone.getZones);
router.post('/zone/add', adminRequired, zone.add);
router.post('/zone/:zid/delete', adminRequired, zone.del);
router.post('/zone/:zid/update', adminRequired, zone.update);

// menu
router.post('/menu/data', menu.getMenus);
router.post('/menu/add', adminRequired, menu.addMenu);
router.post('/menu/:mid/delete', adminRequired, menu.deleteMenu);
router.post('/menu/:mid/update', adminRequired, menu.updateMenu);

// submenu
router.post('/submenu/data', menu.getSubmenus);
router.post('/submenu/add', adminRequired, menu.addSubmenu);
router.post('/submenu/:sid/delete', adminRequired, menu.deleteSubmenu);
router.post('/submenu/:sid/update', adminRequired, menu.updateSubmenu);

// audio
router.post('/audio/data', adminRequired, audio.getData);
router.post('/audio/add', adminRequired, audio.add);
router.post('/audio/:aid/delete', adminRequired, audio.del);
router.post('/audio/:aid/update', adminRequired, audio.update);

// profile
router.post('/profile/data', adminRequired, profile.data);
router.post('/profile/update', adminRequired, profile.update);

// static
router.post('/static/add', adminRequired, static2.add);
router.post('/static/list', adminRequired, static2.list);
router.post('/static/:sid/data', adminRequired, static2.data);
router.post('/static/:sid/update', adminRequired, static2.update);
router.post('/static/:sid/delete', adminRequired, static2.del);

// repo
router.post('/repo/payload', repo.payload);
router.post('/repo/list', repo.list);
router.post('/repo/add', repo.add);
router.post('/repo/:id/delete', repo.del);
router.post('/repo/:id/fetch', repo.fetch);

export default router;

